package com.cyru.statemachine.core;

import com.cyru.statemachine.core.exception.StateMachineAlreadyExistException;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zhangxuchuan
 * date 2022/5/1
 */
public class StateMachines {

    private static final Map<String, StateMachine> stateMachineMap = new ConcurrentHashMap<>();

    public static void register(StateMachine stateMachine) {
        if (stateMachineMap.containsKey(stateMachine.getId())) {
            throw new StateMachineAlreadyExistException("stateMachine id:" + stateMachine.getId() + "is already exists");
        }
        stateMachineMap.put(stateMachine.getId(), stateMachine);
    }

    public static StateMachine getStateMachineById(String id) {
        return stateMachineMap.get(id);
    }


}
